﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Tasks;
using Caliburn.Micro;

namespace CCWP7.CaliburnMicro
{
    public class BrowserPageViewModel : Screen
    {
        readonly IEventAggregator _eventAggregator;

        public BrowserPageViewModel(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
            Uri = "about:blank";
        }

        private string _uri;
        public string Uri
        {
            get
            {
                return _uri;
            }
            set
            {
                _uri = value;

                NotifyOfPropertyChange(() => Uri);
            }
        }

        protected override void OnActivate()
        {
            base.OnActivate();

            Refresh();
        }

        public void OpenInInternetExplorer()
        {
            _eventAggregator.RequestTask<WebBrowserTask>(t => t.Uri = new Uri(Uri));
        }
    }
}
